package com.tuo51.childcare.domain.dailytask;

import com.tuo51.foudation.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * 每日观察记录
 */
@Entity
@Table(name = "user_daily_task")
@EqualsAndHashCode(callSuper = true)
@Data
public class DailyTask extends Domain {

    @Column(columnDefinition = "varchar(32) COMMENT '用户id'")
    private String uid;

    @Column(columnDefinition = "varchar(32) COMMENT '孩子id'")
    private String childrenId;

    @Column(columnDefinition = "varchar(32) COMMENT '能区id'", nullable = false)
    private String title;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '是否已完成' ")
    private Boolean finished = false;

    @Column(columnDefinition = " datetime DEFAULT NOW() COMMENT '完成时间' ")
    private Date finishedAt;

    @Column(columnDefinition = "int default 0 COMMENT '序号'", nullable = false)
    private Integer dailyIndex = 0;

    @Column(columnDefinition = "varchar(32) COMMENT '模板条目id'", nullable = false)
    private String templateId;

    @Column(columnDefinition = "varchar(256) COMMENT '封面图片'")
    private String cover;

    @Column(columnDefinition = "varchar(256) COMMENT '描述'")
    private String description;

    @Column(columnDefinition = "varchar(256) COMMENT '训练频次'")
    private String rate;

    @Column(columnDefinition = "varchar(256) COMMENT '训练时长'")
    private String duration;

    @Column(columnDefinition = "varchar(256) COMMENT '训练周期'")
    private String period;

    @Column(columnDefinition = "varchar(1024) COMMENT '操作指导'")
    private String manual;

    @Column(columnDefinition = "varchar(1024) COMMENT '链接指导'")
    private String ref;

    @Column(columnDefinition = "varchar(256) COMMENT '排期'")
    private Date schedule = new Date();

    public static DailyTask of(String id,
                               String title, Integer dailyIndex, boolean finished, String templateId,
                               String rate, String duration, String period,
                               String manual,
                               String ref){

        DailyTask ret = new DailyTask();

        ret.setDailyIndex(dailyIndex);
        ret.setTitle(title);
        ret.setFinished(finished);
        ret.setTemplateId(templateId);

        ret.setRate(rate);
        ret.setDuration(duration);
        ret.setPeriod(period);
        ret.setManual(manual);
        ret.setRef(ref);

        return ret;
    }

    public static DailyTask of(DailyTaskTemplate template){

        DailyTask ret = new DailyTask();

        ret.setDailyIndex(template.getDailyIndex());
        ret.setTitle(template.getTitle());
        ret.setCover(template.getCover());
        ret.setTemplateId(template.getId());

        ret.setRate(template.getRate());
        ret.setDuration(template.getDuration());
        ret.setPeriod(template.getPeriod());
        ret.setManual(template.getManual());
        ret.setRef(template.getRef());

        return ret;
    }
}
